home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / JOYSTICK.SWG / 0010_Joystick interface.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  2KB  |  80 lines

  1.  
  2. UNIT JoyStick;
  3. (* Public Domain.  Written by Ian Hinson   November 1993 *)
  4.  
  5. INTERFACE
  6.  
  7. PROCEDURE ReadPosns;
  8. { Updates values of JoyA_X, JoyA_Y, JoyB_X, and JoyB_Y }
  9.  
  10. PROCEDURE ReadButtons;
  11. { Updates the state of all buttons }
  12.  
  13. { Call the function for whichever button(s) you want to test
  14.   after updating all their states with a call to ReadButtons. }
  15. FUNCTION JoyA_Button1: BOOLEAN;
  16. FUNCTION JoyA_Button2: BOOLEAN;
  17. FUNCTION JoyB_Button1: BOOLEAN;
  18. FUNCTION JoyB_Button2: BOOLEAN;
  19. FUNCTION AnyButton: BOOLEAN;
  20.  
  21. VAR
  22. { These variables provide the X&Y positions after
  23.   they have been updated by a call to ReadPositions }
  24. JoyA_X, JoyA_Y, JoyB_X, JoyB_Y: WORD;
  25.  
  26.  
  27. IMPLEMENTATION
  28.  
  29. VAR
  30. buttons: SET OF (JoyA_1, JoyA_2, JoyB_1, JoyB_2);
  31.  
  32. PROCEDURE ReadPosns; ASSEMBLER;
  33.    ASM
  34.    mov ah,$84
  35.    mov dx,1
  36.    int $15
  37.    mov JoyA_X,ax
  38.    mov JoyA_Y,bx
  39.    mov JoyB_X,cx
  40.    mov JoyB_Y,dx
  41.    END;
  42.  
  43. PROCEDURE ReadButtons; ASSEMBLER;
  44.    ASM
  45.    mov ah,$84
  46.    mov dx,0
  47.    int $15
  48.    shr al,4
  49.    xor al,$0F
  50.    mov buttons,al
  51.    END;
  52.  
  53. FUNCTION JoyA_Button1: BOOLEAN;
  54.   BEGIN
  55.     JoyA_Button1 := JoyA_1 IN buttons;
  56.   END;
  57.  
  58. FUNCTION JoyA_Button2: BOOLEAN;
  59.   BEGIN
  60.     JoyA_Button2 := JoyA_2 IN buttons;
  61.   END;
  62.  
  63. FUNCTION JoyB_Button1: BOOLEAN;
  64.   BEGIN
  65.     JoyB_Button1 := JoyB_1 IN buttons;
  66.   END;
  67.  
  68. FUNCTION JoyB_Button2: BOOLEAN;
  69.   BEGIN
  70.     JoyB_Button2 := JoyB_2 IN buttons;
  71.   END;
  72.  
  73. FUNCTION AnyButton: BOOLEAN;
  74.   BEGIN
  75.     AnyButton := buttons <> [];
  76.   END;
  77.  
  78. END.
  79.  
  80.